<template>
  <div
    @wheel.stop="handleScroll"
    class="jy-style-height Cultural-box"
    :style="{
      'background-image': `url(${publicUrls + 'free/style17/publicStyle17Bg.png' + '?imageView2/3/format/webp'})`,
    }"
  >
    <div class="copyright-heard">
      <img class="backHome" @click="blankHome" :src="publicUrls + 'free/style17/backHome.png'" alt="" />
      <div class="heard-title">
        <p>文创商品</p>
        <img :src="publicUrls + 'free/style17/otherTitleBg.png'" alt="" />
      </div>
    </div>
    <div class="content-bg">
      <ScrollBoxCom
        color="rgba(50, 43, 37, 1)"
        v-if="Scrollwidth"
        :byid="986761"
        :width="getScrollWidth"
        :checkHeight="true"
      >
        <template #solidBorderExcon>
          <div
            class="right-scroll"
            ref="scrollBox"
            :style="list?.length <= 4 && { justifyContent: 'center', paddingLeft: '0px' }"
          >
            <div class="is-null" v-if="list.length === 0 && !loading">
              <p>暂无文创商品</p>
            </div>
            <div
              class="item-parent"
              v-else
              v-for="(item, index) in list"
              :key="index"
              :class="!store.isMobileType && 'item-parent-mobile'"
            >
              <div class="item">
                <div class="item-img-box" @click="pathLink(item.url)">
                  <img
                    class="item-img"
                    v-if="!item.coverUrl"
                    src="http://101.34.143.36:8890/api/image/387939155165253"
                    alt=""
                  />
                  <img
                    class="item-img"
                    v-else
                    :src="$filters.getLinkUrl(item.coverUrl + '?imageView2/1/w/270/h/270/format/webp')"
                    alt=""
                  />
                </div>
                <p class="item-name">{{ item.name }}</p>
                <div class="item-btm">
                  <span class="item-title1" v-if="item.price">￥</span>
                  <span class="item-title2" v-if="item.price">{{ item.price }}</span>
                  <span class="item-title5" v-if="item.price">参考价</span>
                  <span class="item-title4" v-if="!item.price">暂无价格</span>
                </div>
              </div>
            </div>
          </div>
        </template>
        <template #solidBorderExbar>
          <div class="solidBorder-child"></div>
        </template>
      </ScrollBoxCom>
    </div>
    <div class="content-door">
      <i class="iconfonts">&#xe6dd;</i>
      <span>永不落幕的展览与展示平台</span>
    </div>
    <div class="unit-exbit-upbg"></div>
  </div>
  <MenuNavigation />
</template> 

<script lang="ts">
export default defineComponent({
  name: 'style17',
});
</script>

<script setup lang="ts">
// @ts-nocheck
import MenuNavigation from '@/freeComponents/menuNavigation/index.vue';
import { publicUrls } from '@/utils/minxin';
import { goodsList } from '@/api/goods/goods';
import RightMenu from '../components/rightMenu.vue';
import Logo from '../components/logo.vue';
import FooterHome from '../components/footerHome.vue';
import PublicTitle from '../components/PublicTitle.vue';
import { useRouter, useRoute } from 'vue-router';
import ScrollBoxCom from '../scrollBox.vue';
import { ref, watch, reactive, nextTick, defineComponent } from 'vue';
import { copyrightSave, copyrightInfo } from '@/api/templates/templates';
import { useProjectStore, commonDataStore } from '@/store';
import { storeToRefs } from 'pinia';
import { computed } from 'vue';

const parmas = reactive({
  value: '',
  pageNo: 1,
  pageSize: 100,
});
const topShow = ref(false);
const scrollBox = ref(null);
const percentage = ref(0);
const list = ref([]);
const total = ref(0);
const loading = ref(false);
const store = useProjectStore();
const Scrollwidth = ref();
const router = useRouter();
const route = useRoute();
const Description = ref('');
const init = async () => {
  try {
    if (loading.value) {
      return;
    }
    loading.value = true;
    let res = await goodsList(localStorage.getItem('projectId'), parmas);
    total.value = res.data.total;
    list.value = list.value.concat(res.data.data);
    // list.value = [];
    loading.value = false;
  } catch {
    loading.value = false;
  }
};
init();

let viewportwidth = window.innerWidth;
Scrollwidth.value = (viewportwidth / 900) * 560;

const getScrollWidth = computed(() => {
  let widths = (window.innerWidth / 900) * 560;
  return widths;
});

const handleScroll = (event) => {
  event.preventDefault(); // 阻止默认滚动行为
  const { deltaY } = event;

  // 获取滚动内容的 DOM 元素
  const contentEl = scrollBox.value;

  // 将滚动盒子向前滚动
  contentEl.scrollLeft += deltaY;
  if (contentEl.scrollWidth > contentEl.clientWidth) {
    if (
      contentEl.scrollWidth < contentEl.scrollLeft + contentEl.clientWidth + 100 &&
      !loading.value &&
      list.value.length < total.value
    ) {
      parmas.pageNo = parmas.pageNo + 1;
      init();
    }
    nextTick(() => {
      const { scrollLeft, clientWidth, scrollWidth } = scrollBox.value;
      if (scrollLeft > 100) {
        topShow.value = true;
      }
      if (scrollLeft < 100) {
        topShow.value = false;
      }
      const newScrollPercentage = Math.floor((scrollLeft / (scrollWidth - clientWidth)) * 100);
      percentage.value = newScrollPercentage == 99 ? 100 : newScrollPercentage;
    });
  }
};
const emitTop = () => {
  //点击回到列表最左侧
  scrollBox.value.scrollLeft = 0;
  percentage.value = 0;
  topShow.value = false;
};
const pathLink = (url?: string) => {
  if (!url) {
    return;
  }
  window.open(url, '_blank');
};
const blankHome = () => {
  store.menuId = null;
  router.push({ name: route.meta.loopType ? 'exhibitionHome' : 'templateedit' });
};
</script>

<style scoped lang="less">
.Cultural-box {
  position: relative;
  display: flex;
  flex-direction: column;
  width: 100%;
  padding-top: 118px;
  padding-bottom: 0px;
  background-size: cover;
  background-repeat: no-repeat;
  background-position: top center;
}

// 头部
.copyright-heard {
  width: 100%;
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0 76px;
  margin-bottom: 24px;
  .heard-title {
    width: 350px;
    height: 67px;
    display: flex;
    align-items: center;
    justify-content: center;
    position: relative;
    ::v-deep p {
      font-family: SourceHanSerifCN-Bold;
      font-size: 36px;
      color: #fed681;
      line-height: 67px;
      margin: 0 8px;
      position: relative;
      z-index: 1;
    }
    img {
      width: 100%;
      height: 100%;
      position: absolute;
      top: 0;
      left: 0;
    }
  }
  .backHome {
    cursor: pointer;
    width: 32px;
    height: 32px;
    position: absolute;
    left: 56px;
    top: 50%;
    transform: translateY(-50%);
  }
}

// 内容
.content-bg {
  width: calc(100% - 120px);
  height: 100%;
  padding: 0 75px;
  display: flex;
  align-items: center;
  justify-content: center;
  margin: 0 auto;
  overflow: hidden;
  // 空状态
  .is-null {
    margin: 0 auto;
    margin-bottom: 60px;
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    ::v-deep p {
      font-size: 16px;
      color: rgba(255, 227, 162, 0.9);
      line-height: 22px;
      text-indent: 0;
    }
  }

  .right-scroll {
    width: 100%;
    display: flex;
    align-items: center;
    height: 482px;
    &::-webkit-scrollbar {
      display: none;
    }
  }
  // 单个展品样式
  .item-parent {
    width: 282px;
    cursor: pointer;
    margin-right: 20px;
    flex-shrink: 0;
    transition: all 0.3s;
    &:last-child {
      margin-right: 4px;
    }
    &:first-child {
      margin-left: 4px;
    }
    .item {
      width: 100%;
      display: flex;
      flex-direction: column;
      align-items: center;
      // 展品图片
      .item-img-box {
        overflow: hidden;
        cursor: pointer;
        display: flex;
        align-items: center;
        justify-content: center;
        position: relative;
        width: 100%;
        height: 360px;
        flex-shrink: 0;
        position: relative;
        background: url(https://static.jiyi.show/free/style17/otherBg.png) no-repeat center/100% 100%;
        padding: 8px 13px 8px 8px;
        // &:hover img {
        //   transform: scale(1.5);
        // }
        // .arrow {
        //   width: 16px;
        //   height: 16px;
        //   position: absolute;
        //   z-index: 1;
        //   &:nth-child(1) {
        //     top: 8px;
        //     left: 8px;
        //   }
        //   &:nth-child(2) {
        //     top: 8px;
        //     right: 8px;
        //     transform: rotate(90deg);
        //   }
        //   &:nth-child(3) {
        //     bottom: 8px;
        //     left: 8px;
        //     transform: scale(-1) rotate(90deg);
        //   }
        //   &:nth-child(4) {
        //     bottom: 8px;
        //     right: 8px;
        //     transform: rotate(180deg);
        //   }
        // }
        .item-img {
          position: relative;
          width: 100%;
          height: 100%;
          object-fit: contain;
          transition: all 0.3s;
        }
      }
      .item-name {
        width: 100%;
        font-size: 18px;
        color: #fed681;
        line-height: 24px;
        overflow: hidden;
        text-overflow: ellipsis;
        white-space: nowrap;
        margin-top: 16px;
        text-indent: 0rem !important;
        padding: 0 12px;
      }
      // 价格文本
      .item-btm {
        width: 100%;
        display: flex;
        align-items: baseline;
        margin-top: 4px;
        padding: 0 12px;
        // font-family: SourceHanSerifCN;
        // ￥
        .item-title1 {
          font-size: 22px;
          color: #fed681;
          line-height: 30px;
        }
        // 价格
        .item-title2 {
          font-size: 22px;
          color: #fed681;
          line-height: 30px;
        }
        // 参考价文本
        .item-title5 {
          font-size: 12px;
          color: rgba(254, 214, 129, 0.6);
          margin-right: 4px;
          line-height: 24px;
        }
        // 暂无价格
        .item-title4 {
          font-family: SourceHanSerifCN;
          font-weight: 400;
          font-size: 16px;
          line-height: 34px;
          color: rgba(254, 214, 129, 0.6);
        }
      }
    }
  }

  // 滚动条轨道
  .solidBorder-child {
    width: 100%;
    height: 4px;
    background: rgba(255, 227, 162, 0.4);
    border-radius: 2px;
  }
  ::v-deep .scrollBar {
    border-radius: 3px;
    background: #ffe3a2;
  }
  // 滚动条按钮
  :deep(.templatestyle1-scroll-box-tumb) {
    height: 32px;
    display: flex;
    align-items: center;
    img {
      width: 24px !important;
      height: 16px !important;
      margin-top: 3px;
    }
  }
}

// 底部logo
.content-door {
  width: 100%;
  height: 40px;
  display: flex;
  justify-content: center;
  align-items: center;
  margin-top: 8px;
  background: rgba(70, 23, 7, 0.5);
  .iconfonts {
    font-size: 26px;
    background: linear-gradient(270deg, #e7a859 0%, #ffdaac 100%);
    background-clip: text;
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    line-height: 32px;
  }
  span {
    font-family: PingFang SC;
    font-size: 16px;
    line-height: 32px;
    background: linear-gradient(270deg, #e7a859 0%, #ffdaac 100%);
    background-clip: text;
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    margin-left: 20px;
  }
}
</style>